<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler'>
      <f-search-form-item label='订单编号' name='orderNo' />
      <f-search-form-item label='部门' ref='dept' name='deptId' slot='advanced' type='select' :data='api.hyorder.listByCompanyId' valueKey='deptId' label-key='deptName' />
      <f-search-form-item label='发货日期' type='range' name='beginDate' />
      <f-search-form-item label='发货方式' type='select' slot='advanced' name='customBondType' :data='api.busCommon.sendType' />
      <f-search-form-item label='单位名称' name='customName' slot='advanced' />
    </f-search-form>
    <f-table ref='table' size='small' rowKey='paymentId' :showSetting='false' setting-key='tasktodo_calculate_tab1' :tableColumns='columns' :scroll='{x:true}' :multiple='false' :operator='operator' :params='queryParam' :api='api.tasktodo' handler='hyCalApproveTab1ListHandler'>
       <span slot='orderType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text=="CHA"'>销售</a-tag>
           <a-tag color='#FF0000' v-if='text=="CHC"'>退货</a-tag>
           <a-tag color='purple' v-if='text=="PZ"'>票折</a-tag>
       </span>
       <span slot='orderNo' slot-scope='text, record, index'>
            <span v-clipboard:copy='text' v-clipboard:success='onCopy' style='cursor:pointer'>{{ text }}</span>
        </span>
      <span slot='outOrderNo' slot-scope='text, record, index'>
            <span v-clipboard:copy='text' v-clipboard:success='onCopy' style='cursor:pointer'>{{ text }}</span>
        </span>
      <span slot='sendType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text==1'>现款</a-tag>
            <a-tag color='#FF0000' v-if='text==2'>预收款</a-tag>
            <a-tag color='#87d068' v-if='text==3'>资保金</a-tag>
            <a-tag color='purple' v-if='text==4'>全额资信</a-tag>
      </span>
      <span slot='deptType' slot-scope='text, record, index'>
        <a-tag color='#87d068' v-if='text=="ZS"'>招商</a-tag>
        <a-tag color='#108ee9' v-if='text=="ZY"'>自营</a-tag>
      </span>
      <span slot='taskName' slot-scope='text, record, index'>
          <a-tag color='#87d068' @click='processImg(record,record.applyIncId)'>{{ record.taskName }}</a-tag>
      </span>
      <span slot='action' slot-scope='text, record'>
          <template>

            <a v-if="(record.assignee==''||record.assignee=='')" @click='claimTask(record)'>认领</a>
            <a-divider type='vertical' v-if="(record.assignee==''||record.assignee=='')" />
            <a v-if="record.assignee!='' || superAdmin" @click='$refs.caclulateApproveDrawer.showDrawer(record)'>办理</a>
            <a-divider type='vertical' v-if="record.assignee!='' || superAdmin" />
          </template>
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
               <a-menu-item v-if="record.assignee===$store.getters.userInfo.nickName && record.endTime==''">
                <a href='javascript:;' @click='unClaimTask(record)'>取消认领</a>
              </a-menu-item>
              <a-menu-item>
                <a href='javascript:;' @click='processImg(record,record.applyIncId)'>审批进度</a>
              </a-menu-item>
               <a-menu-item v-if='superAdmin'>
                 <a href='javascript:;' @click='deleteProcessInstance(record.applyIncId,"hyCalculateProcDeleteHandler")'>撤销审批</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
    <caclulate-approve-drawer ref='caclulateApproveDrawer' @success='onLoad'></caclulate-approve-drawer>
  </div>
</template>
<script>

import api from "../../js/api"
import ProcessImage from "../../../flowable/process/process_image"
import { processMixins } from "@/core/mixins/processMixins"
import CaclulateApproveDrawer from "@/views/module/haiying/tasktodo/calculate/components/caclulate_approve_drawer"
import Vue from 'vue'

export default {
  name: "TodoNo",
  components: {
    CaclulateApproveDrawer,
    ProcessImage
  },
  mixins: [processMixins],
  data() {
    let me = this
    //操作按钮
    let operator = []

    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      companyList: [],
      processInstanceId: "",
      superAdmin: this.superAdmin,
      processImageVisible: false,
      // 表头
      columns:[],
      operator: operator
    }
  },
  created() {
    this.columns=this.getColumns();
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    },
    unClaimTask(task) {
      this.http.put(this, {
        url: this.api.tasktodo.unclaim,
        data: {
          taskId: task.taskId
        },
        success(me, data) {
          me.$refs["table"].refresh(false)
        }
      })
    },
    getColumns(){
     let companyList= Vue.ls.get("companyList");
     return [
        {
          title: "序号",
          width: "50px",
          align: "center",
          fixed: "left",
          customRender: (text, record, index) => index + 1
        },
       {
         title: "发货日期",
         align: "center",
         width: "100px",
         fixed: "left",
         dataIndex: "sendDate"
       },
       {
         title: "订单编号",
         align: "center",
         width: "130px",
         dataIndex: "orderNo",
         scopedSlots: { customRender: "orderNo" }
       },
        {
          title: "出库单号",
          align: "center",
          width: "130px",
          dataIndex: "outOrderNo",
          scopedSlots: { customRender: "outOrderNo" }
        },
       {
         title: "订单类型",
         align: "center",
         width: "80px",
         dataIndex: "orderType",
         scopedSlots: { customRender: "orderType" }
       },
        {
          title: "业务类型",
          align: "center",
          width: "80px",
          dataIndex: "deptType",
          scopedSlots: { customRender: "deptType" },
          filters: [
            {
              text: "招商",
              value: "ZS"
            },
            {
              text: "自营",
              value: "ZY"
            }
          ],
          filterMultiple: false
        },
       

        {
          title: "部门",
          align: "left",
          ellipsis: true,
          width: "120px",
          dataIndex: "deptName"
        },

        {
          title: "业务员",
          align: "left",
          ellipsis: true,
          width: "100px",
          dataIndex: "saleManName"
        },
        {
          title: "单位名称",
          align: "left",
          ellipsis: true,
          width: "120px",
          dataIndex: "customName"
        },
        {
          title: "发货方式",
          align: "center",
          dataIndex: "sendType",
          scopedSlots: { customRender: "sendType" }
        },
        {
          title: "制单人",
          align: "center",
          width: "100px",
          dataIndex: "nickName"
        },
        {
          title: "创建日期",
          align: "center",
          width: "130px",
          dataIndex: "createTime"
        },
        {
          title: "审批状态",
          align: "center",
          dataIndex: "taskName",
          fixed: "right",
          scopedSlots: { customRender: "taskName" }
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "150px",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ]
    }
  }
}
</script>
